package C;

import java.util.Arrays;
import java.util.Scanner;

public class C76 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int m = Integer.parseInt(sc.nextLine());

        System.out.println(getResult(n,m));
    }

    public static int getResult(int n,int m) {
        if (n<3||n>7) return -1;
        int start = 1,end = 1;
        int record=n;
        while(n>0) {
            start *= 10;
            end*=10;
            n--;
        }
        start/=10;
        System.out.println("start="+start+" end="+end);
        int count=0;
        for (int i=start;i<end;i++) {
            int x = Arrays.stream((i + "").split(""))
                    .mapToInt(Integer::parseInt).map(c->(int)Math.pow(c,record))
                    .sum();
            if (x==i) count++;
//            System.out.println("i="+i+" x="+x+" count="+count);
            if (count==(m+1)) return i;
        }
        return -1;
    }
}
